home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -in_the_mag- / reader_requests / scilab / demos / pendulum / macros.sci next >
Text File  |  1999-09-16  |  3KB  |  121 lines

  1. function []=anim(x,teta,amode,frein)
  2. //anim(x,teta) animated plot
  3. //!
  4. [lhs,rhs]=argn(0)
  5. if rhs <=2, amode =0 ;end
  6. if rhs <=3, frein =1 ;end
  7. maxp=maxi(x+l*sin(teta));minp=mini(x+l*sin(teta));
  8. maxx=maxi([x,maxp]);minx=mini([minp,x])
  9. isoview(minx,maxx,-l,l);
  10. [m,n]=size(x);
  11. xset("alufunction",6);
  12. xset("thickness",2);
  13. if amode=0 then 
  14.   for k=1:n,for j=1:frein,
  15.           xsegs([x(k),x(k)+l*sin(teta(k))],[0, l*cos(teta(k))]);
  16.           xsegs([x(k),x(k)+l*sin(teta(k))],[0, l*cos(teta(k))]);
  17.           end;end
  18.   k=n;xsegs([x(k),x(k)+l*sin(teta(k))],[0, l*cos(teta(k))]);
  19.   xset("alufunction",3);//xpause();
  20. else
  21.  isoview(minx,maxx,-l,l);
  22.  for k=1:n,dpnd1(x(k),teta(k));dpnd1(x(k),teta(k));end;
  23.   xset("alufunction",3);//xpause();
  24. end
  25. xset("thickness",1);
  26.  
  27.  
  28. function []=dpnd()
  29. //dpnd() scheme of experiment
  30. //!
  31. isoview(0,100,0,100);
  32. lc=20,
  33. hc=10,
  34. lb=40,
  35. teta=.25,
  36. xg=40,
  37. y1=25,
  38. y2=y1+hc,
  39. yg=y1+hc/2,
  40. x1=xg-lc/2;x2=xg+lc/2,
  41. xpoly([x1 x2 x2 x1 x1],[y1,y1,y2,y2,y1],"lines",1),
  42. xsegs([xg,xg+lb*sin(teta)],[y2,y2+lb*cos(teta)]),
  43. xarc(x1+lc/10-2.5,y1-2.5+2.5,5,5,0,360*64);
  44. xarc(x2-5+lc/10-2.5,y1-2.5+2.5,5,5,0,360*64);
  45. xsegs([10 90],[y1-5 y1-5]); 
  46. xarrows([x2 x2+10],[yg yg],3.0);
  47. xstring(x2+20,yg,'u (force)',0,0);
  48. xset("dashes",1);xsegs([xg xg],[y2 y2+lb]);xstring(xg,y2+lb,' teta',0,0);
  49. xset("default");
  50.  
  51.  
  52. function []=dpnd1(x,theta)
  53. //dpnd() scheme
  54. //!
  55. lc=l/4,
  56. hc=l/5,
  57. xg=x,
  58. y1=0,
  59. y2=y1+hc,
  60. yg=y1+hc/2,
  61. x1=xg-lc/2;x2=xg+lc/2,
  62. xpoly([x1 x2 x2 x1 x1],[y1,y1,y2,y2,y1],"lines",1),
  63. xsegs([xg,xg+l*sin(theta)],[y2,y2+l*cos(theta)]),
  64. r=lc/4
  65. xarc(x1+lc/10,y1,r,r,0,360*64);
  66. xarc(x2-r-lc/10,y1,r,r,0,360*64);
  67.  
  68.  
  69. function [xdot]=ivpd(t,x)
  70. //ydot=ivpd(t,y) non linear equations of the pendulum
  71. // y=[x;d(x)/dt,teta,d(teta)/dt].
  72. // mb, mc, l must be predefined 
  73. //!
  74. g=9.81;
  75. u=0
  76. qm=mb/(mb+mc)
  77. cx3=cos(x(3))
  78. sx3=sin(x(3))
  79. d=4/3-qm*cx3*cx3
  80. xd4=(-sx3*cx3*qm*x(4)**2+2/(mb*l)*(sx3*mb*g-qm*cx3*u))/d
  81. //
  82. xdot=[x(2);
  83.       (u+mb*(l/2)*(sx3*x(4)**2-cx3*xd4))/(mb+mc);
  84.       x(4);
  85.       xd4]
  86.  
  87.  
  88.  
  89. function [y,xdot]=pendu(x,u)
  90. //[y,xdot]=pendu(x,u) input (u) - output (y) function of the pendulum
  91. //!
  92. g=9.81;
  93. qm=mb/(mb+mc)
  94. cx3=cos(x(3))
  95. sx3=sin(x(3))
  96. d=4/3-qm*cx3*cx3
  97. xd4=(-sx3*cx3*qm*x(4)**2+2/(mb*l)*(sx3*mb*g-qm*cx3*u))/d
  98. //
  99. xdot=[x(2);
  100.       (u+mb*(l/2)*(sx3*x(4)**2-cx3*xd4))/(mb+mc);
  101.       x(4);
  102.       xd4]
  103. //
  104. y=[x(1);
  105.    x(3)]
  106.  
  107.  
  108.  
  109. function [xdot]=regu(t,x)
  110. //xdot=regu(t,x) simulation of the compound system
  111. // pendulum - observer - compensator
  112. //!
  113. xp=x(1:4);xo=x(5:8);
  114. u =-kr*xo   //control
  115. [y,xpd]=pendu(xp,u)
  116. xod=(f-k*h)*xo+k*y+g*u
  117. xdot=[xpd;xod]
  118.  
  119.  
  120.  
  121.